/////////////////
//  PREAMBLE  //
////////////////


/*	program:	Analysis-3-Early-Republic.do
	author:		David Bateman */

/******************************************************************************/
/***                                                                        ***/
/*** File provides a series of analyses of turnout in the early Republic.   ***/
/*** It uses the Lampi data made available by the American Antiquarian      ***/
/*** society. From this database, a unique identifier was generated for     ***/
/*** each distinct place / office across all its occurrences in the data.   ***/
/*** This allows us to examine the number of votes cast in every election   ***/
/*** in that electoral unit (place/office). While we do not know the adult  ***/
/*** male population, we can examine systematic changes in the number of    ***/
/*** votes cast.                                                            ***/
/***                                                                        ***/
/*** We calculate a z-score as a standardized measure in turnout. The score ***/
/*** is calculated for each place/office across all elections in that unit  ***/
/*** observed in the database.                                              ***/
/***                                                                        ***/
/******************************************************************************/

*** Stata changed its random number generator with version 14. Later
*** versions will not produce the same results, even with the same seed.
version 13.1
set seed 100
cd "..\..\Dataverse\"
use "Data\Early-Republic-Votes-All-States.dta",  clear

*** Set the panel shape to the data. The basic unit is the place/office. 
xtset newID date1
egen state1	= group(state)

*** When did suffrage reform go into effect?
gen reform 		= . 
replace reform	= -57351 if state=="Maryland" 
replace reform	= -51683 if state=="Connecticut" 
replace reform	= -50344 if state=="New York" 
replace reform	= -50618 if state=="Massachusetts" 
replace reform	= -55563 if state=="New Jersey" 
replace reform	= -54434 if state=="South Carolina" 
replace reform	= -61197 if state=="Delaware" 

*** Index which states made a substantial change
gen refState	= (state=="Maryland" | state=="Connecticut" | state=="New York"		///
					| state=="Massachusetts" | state=="New Jersey" | state=="South Carolina" 	///
					| state=="Delaware")

*** Identify moment of implementation
*** MD - Amendment passed second time on 23rd Dec 1803
gen pre		= 1 if (date1<-57351) & state=="Maryland" 	
*** CT - Constitution ratified on first Monday of Oct 1818. In Nov. 1817 a 
*** modification of the existing election law was passed, repealing the "stand-up" law. 
*** In June 1818 a suffrage law passed that extended the right to vote. 
*** A constitutional convention would be called in 1818 on a broad franchise and would ratify this change.
replace pre	= 1 if (date1<-51683) & state=="Connecticut" 
*** NY - Constitution ratified in January 1822 and went into effect on Dec 31 1822. Suffrage went into effect 1st Monday of March 1822
replace pre	= 1 if (date1<-50344) & state=="New York"		
replace pre	= 2 if (date1<-50344) & state=="New York" & (office=="Governor" | office=="State Senate")
*** MA - Constitutional amendments ratified in April/May of 1821. Presented to General Court on May 31 and certified May 24
replace pre	= 1 if (date1<-50618) & state=="Massachusetts"
*** NJ - Statute altering qualifications enacted on Nov 16 - "from and after the passing of this act." 	
replace pre	= 1 if (date1<-55563) & state=="New Jersey"	
*** SC - Constitutional amendment ratified on December 19, 1810.
replace pre	= 2 if (date1<-54434) & state=="South Carolina"	
*** DE - Constitution goes into effect on June 12, 1792. 
replace pre	= 1 if (date1<-61197) & state=="Delaware"		
*** VA, RI, LA, and NC (senate) have high qualifications throughout early Republic
replace pre = 2 if state=="North Carolina" & office=="State Senate"
replace pre = 2 if state=="Virginia"
replace pre = 2 if state=="Rhode Island"
replace pre = 2 if state=="Louisiana"
replace pre = 0 if pre==.

*** Generate a new calculation of the total vote, based on the number of offices.
*** This information was collected for all reform states. Other than Congress, it 
*** was not collected for most non-reform states since this required finding often
*** yearly changes in county apportionment. 					
gen totalNew		= .
replace totalNew	= int(total/membersLA) if membersLA!=. & id1==".MSA"
replace totalNew	= int(total/membersSEN) if membersSEN!=. & id1==".MSS"
replace totalNew	= int(total/membersMC) if membersMC!=. & id1==".MC"
replace totalNew	= int(total/membersSEN) if membersSEN!=. & id1==".nomMSS"
replace totalNew	= int(total/membersMC) if membersMC!=. & id1==".nomMC"
replace totalNew	= int(total) if id1==".governor"

*** We want a standardized measure of change in the number of votes cast. 
*** To do this, we calculate z-scores, using the average across the whole period.

tempvar a b 
bys newID (date1): egen `a' = mean(totalNew)
bys newID (date1): egen `b' = sd(totalNew)
bys newID (date1): gen zvote = (totalNew-`a')/`b'

*** Placebo for all states (randomly chosen between first and last year in dataset)
*** Constrain so that minimum year is at least 1800 and no later than 1824.
tempvar a b c
bys state1 (year): egen `a' = min(year)
replace `a' 				= 1800 if `a'<1800 
bys state1 (year): egen `b' = max(year) 
replace `b' 				= 1824 if `b'>1824 
bys state1: gen `c'	= (`a'+(`b'-`a')* runiform()) if _n==1 
bys state1: egen placebo = mean(`c') 
replace placebo = year<placebo 

***********		Analyses of standardized turnout in reform states 	************

*** Estimate the effect of different franchise qualifications on standardized
*** turnout within specific places/offices, for all states and then state by state.
*** Each state is estimated with different time windows (5, 10, 15, and 20 years
*** before and after reform). The main text covers 5 years before and 5 years
*** after reform (10 year wind). The other specifications are in the supplemental
*** material.

*** For each state, I also create standardized turnout measures using only that 
*** these windows of time, rather than the full period. The full period is reported
*** in the text. 

eststo drop est*
*** Estimate a fixed effect model for all states. The estimate is of change within
*** the zvote score for votes cast in a place for an office across time.
eststo all: xtreg zvote i.pre year, fe cluster(state1)
margins, over(pre) 
marginsplot, recast(scatter) xsc(reverse) name(all, replace) ///
		plotopts(lw(thin) mlc(black) mcol(white)) ciopts(lw(thin) lc(black))	///
		graphreg(col(none)) ylabel(, nogrid angle(h) labsize(vsmall)) ytitle("")	///
		xtitle("") xlabel(0 "Low" 1 "Medium" 2 "High", labsize(vsmall))	title("All States", size(small) col(black) )

*** Estimate effect within each enfranchising states. This can take a bit of time, 
*** so I have set it to run quietly with displays showing what is being estimated.
levelsof state if refState==1, local(reform)
qui foreach x in `reform' {
	noisily di in yellow "State: " in red "`x'"
	foreach l in 5 10 15 20 {
		noisily di in yellow "Time window: " in red "`l' years before and `l' years after"
		local y = subinstr("`x'", " ","",.)
		qui summ year if pre==0 & state=="`x'"
		local k = r(min)
		local year_1 = `k'-`l'
		local year_2 = `k'+`l'
		
		*** Generate locally specified z-scores
		tempvar a b c
		qui bys newID (date1): egen `a' = mean(totalNew) if year>=`year_1' & year<=`year_2' & state=="`x'"
		qui bys newID (date1): egen `b' = sd(totalNew)   if year>=`year_1' & year<=`year_2' & state=="`x'"
		qui bys newID (date1): gen `c' = (totalNew-`a')/`b'  if year>=`year_1' & year<=`year_2' & state=="`x'"
		
		qui eststo ref_`y'_`l'	: xtreg zvote i.pre if refState==1 & state=="`x'" & year>=`year_1' & year<=`year_2', fe robust	
		
		if `l'==5 {
			qui eststo ref_`y'_local: xtreg `c' i.pre if refState==1 & state=="`x'" & year>=`year_1' & year<=`year_2', fe robust
			margins, over(pre)
			marginsplot, recast(scatter) xsc(reverse) name(ref_`y', replace) ///
				plotopts(lw(thin) mlc(black) mcol(white)) ciopts(lw(thin) lc(black))	///
				graphreg(col(none)) ylabel(, nogrid angle(h) labsize(vsmall)) ytitle("")	///
				xtitle("") xlabel(0 "Low" 1 "Medium" 2 "High", labsize(vsmall))	title("`x'", size(small) col(black) )
			}
	}
}

eststo placebo: xtreg zvote placebo year , fe cluster(state1)
margins, over(placebo) at(year=1810)
marginsplot, recast(scatter) xsc(reverse) name(placebo, replace) ///
		plotopts(lw(thin) mlc(black) mcol(white)) ciopts(lw(thin) lc(black))	///
		graphreg(col(white)) ylabel(, nogrid angle(h) labsize(vsmall)) ytitle("")	///
		xtitle("") xlabel(0 "Post-Placebo" 1 "Pre-Placebo" , labsize(vsmall))	title("All States (Placebo)", size(small) col(black) )


***********************		Figure in main text 		************************
gen group 		= state
replace group	= "No Change" if refState==0 

bys date1 state: egen x = mean(zvote)
tempvar a b c d
bys year group: egen `a' = mean(zvote) 
bys year group: egen `b' = pctile(zvote), p(25)
bys year group: egen `c' = pctile(zvote), p(75) 

bys year group: gen x1 =`a' if _n==1
bys year group: gen x25 =`b' if _n==1
bys year group: gen x75 =`c' if _n==1

	
levelsof group, local(levels)
foreach x in `levels' {
	local y = subinstr("`x'"," ","",.) 
	* trim outliers for graphing purposes

	qui summ reform if group=="`x'"
	local k = r(min)
	if "`x'" == "New York"  {
		tw (scatter zvote date1 if group=="`x'" & zvote<=3 & zvote>=-3, msy(o) jitter(.5) mc(gs15) msize(vsmall) mlw(vvvthin) mlc(gs14) )	///
			(lpolyci zvote date1 if pre==2 & group=="`x'", clcol(black))	///
			(lpolyci zvote date1 if pre==1 & group=="`x'", clcol(gs9))	///
			(lpolyci zvote date1 if pre==0 & group=="`x'" & id1!=".governor" & id1!=".MSS", clcol(gs9))	///
			(lpolyci zvote date1 if pre==0 & group=="`x'" & (id1==".governor" | id1==".MSS"), clcol(black)), ///
			yline(2, lw(thin) lc(gs14)) yline(0, lw(thin) lc(black)) yline(-2, lw(thin) lc(gs14)) xline(`k', lw(thin) lp(dash) lc(black))				///
			graphregion(color(white) margin(tiny)) plotregion(lcolor(black)) ylabel(none, angle(h) labsize(vsmall) nogrid) xlab(none, labsize(vsmall) format(%tdCCYY)) ///
				title("`x'", size(small) col(black) box bexpand) note("") legend(off) name("`y'", replace)
	}
	else if "`x'" == "South Carolina" {
		tw (scatter zvote date1 if group=="`x'" & zvote<=3 & zvote>=-3, msy(o) jitter(.5) mc(gs15) msize(vsmall) mlw(vvvthin) mlc(gs14) )	///
			(lpolyci zvote date1 if pre==2 & group=="`x'", clcol(black))	///
			(lpolyci zvote date1 if pre==0 & group=="`x'", clcol(black)), ///
			yline(2, lw(thin) lc(gs14)) yline(0, lw(thin) lc(black)) yline(-2, lw(thin) lc(gs14)) xline(`k', lw(thin) lp(dash) lc(black))				///
			graphregion(color(white) margin(tiny)) plotregion(lcolor(black)) ylabel(none, angle(h) labsize(vsmall) nogrid) xlab(none, labsize(vsmall) format(%tdCCYY)) ///
				title("`x'", size(small) col(black) box bexpand) note("") legend(off) name("`y'", replace)
	}
	else if "`x'" == "No Change" {
		tw (scatter zvote date1 if group=="`x'" & zvote<=3 & zvote>=-3, msy(o) jitter(.5) mc(gs15) msize(vsmall) mlw(vvvthin) mlc(gs14) )	///
			(lpolyci zvote date1 if pre==2 & group=="`x'", clcol(black))	///
			(lpolyci zvote date1 if pre==0 & group=="`x'", clcol(gs9)), ///
			yline(2, lw(thin) lc(gs14)) yline(0, lw(thin) lc(black)) yline(-2, lw(thin) lc(gs14))				///
			graphregion(color(white) margin(tiny)) plotregion(lcolor(black)) ylabel(none, angle(h) labsize(vsmall) nogrid) xlab(none, labsize(vsmall) format(%tdCCYY)) ///
				title("`x'", size(small) col(black) box bexpand) note("") legend(off) name("`y'", replace)
	}
	else {
		tw (scatter zvote date1 if group=="`x'" & zvote<=3 & zvote>=-3, msy(o) jitter(.5) mc(gs15) msize(vsmall) mlw(vvvthin) mlc(gs14) )	///
			(lpolyci zvote date1 if pre==1 & group=="`x'", clcol(gs9))	///
			(lpolyci zvote date1 if pre==0 & group=="`x'", clcol(gs9)), ///
			yline(2, lw(thin) lc(gs14)) yline(0, lw(thin) lc(black)) yline(-2, lw(thin) lc(gs14)) xline(`k', lw(thin) lp(dash) lc(black))				///
			graphregion(color(white) margin(tiny)) plotregion(lcolor(black)) ylabel(none, angle(h) labsize(vsmall) nogrid) xlab(none, labsize(vsmall) format(%tdCCYY)) ///
				title("`x'", size(small) col(black) box bexpand) note("") legend(off) name("`y'", replace)
	}	

}


***************			Calibrate to NYS and NC results		********************

*** Our z-score analysis can be calibrated to the causally identified results in 
*** NC and NY. For this, we need to calculate a standardized turnout measure for
*** each distinct place regardless of office, and then compare the magnitude of 
*** turnout changes across offices. 

preserve
	*** We first create a "place" identifier in the Lampi data. 
	gen place 		= ID if state=="New York" | state=="North Carolina"
	replace place 	= subinstr(place,"ny.MSA.", "",.) 
	replace place 	= subinstr(place,"ny.MSS.", "",.)
	replace place 	= subinstr(place,"ny.MC.", "",.)
	replace place 	= subinstr(place,"ny.governor.", "",.)
	replace place 	= subinstr(place,"nc.MSS.", "",.)
	replace place 	= subinstr(place,"nc.MSA.", "",.)
	replace place 	= subinstr(place,"nc.MC.", "",.)
	replace place	= regexr(place, "^([a-zA-Z0-9]+)\(district\)\.","")

	*** Next create new z-vote measure, based on turnout in specific places regardless
	*** of the office. These are calculated for the five year period preceding suffrage 
	*** reform in New York (and for all observations in North Carolina)
	tempvar a b 
	bys place date1: egen `a' 	= mean(totalNew) if (state=="New York" & year>=1816 & year<=1821) | state=="North Carolina"
	bys place date1: egen `b' 	= sd(totalNew) 	 if (state=="New York" & year>=1816 & year<=1821) | state=="North Carolina"
	bys place date1: gen zvote1 = (totalNew-`a')/`b' if (state=="New York" & year>=1816 & year<=1821) | state=="North Carolina"

	*** Identify the high threshold offices
	gen highThreshold 		= 1 if (office=="Governor" | office=="State Senate") & state=="New York" & pre==2
	replace highThreshold 	= 1 if (office=="State Senate") & state=="North Carolina"
	replace highThreshold 	= 0 if (office=="Assembly" | office=="U.S. House of Representatives") & state=="New York"
	replace highThreshold 	= 0 if (office=="House of Commons" | office=="U.S. House of Representatives") & state=="North Carolina"

	egen tempID = group(place date)
	xtset tempID
	
	
	xtreg zvote1 highThreshold if state=="New York" & year>=1816 & year<=1821 & level==2, fe robust
	xtreg zvote1 highThreshold if state=="North Carolina" & year>=1816 & year<=1821 & level==2, fe robust
restore

******************		Calculate % change in turnout	************************
preserve 
	xtset newID date1
	levelsof state if (refState==1) | state=="North Carolina", local(reform)
	
	gen highThreshold 		= 1 if (office=="Governor" | office=="State Senate") & state=="New York" & pre==2
	replace highThreshold 	= 1 if (office=="State Senate") & state=="North Carolina"
	replace highThreshold 	= 0 if (office=="Assembly" | office=="U.S. House of Representatives") & state=="New York"
	replace highThreshold 	= 0 if (office=="House of Commons" | office=="U.S. House of Representatives") & state=="North Carolina"
	
	gen place 		= ID if state=="New York" | state=="North Carolina"
	replace place 	= subinstr(place,"ny.MSA.", "",.) 
	replace place 	= subinstr(place,"ny.MSS.", "",.)
	replace place 	= subinstr(place,"ny.MC.", "",.)
	replace place 	= subinstr(place,"ny.governor.", "",.)
	replace place 	= subinstr(place,"nc.MSS.", "",.)
	replace place 	= subinstr(place,"nc.MSA.", "",.)
	replace place 	= subinstr(place,"nc.MC.", "",.)
	replace place	= regexr(place, "^([a-zA-Z0-9]+)\(district\)\.","")

	qui foreach x in `reform' {

		capture drop _*
		
		qui summ year if pre==0 & state=="`x'"
		local k = r(min)
		local year_1 = `k'-5
		local year_2 = `k'+5
		
		*** Impute the results from Table 5
		if "`x'"=="Delaware" {
			loc y = -0.93
		}
		else if "`x'"=="Connecticut" {
			loc y = .78
		}
		else if "`x'"=="Maryland" {
			loc y = -.18
		}
		else if "`x'"=="New Jersey" {
			loc y = -.49
		}	
		else if "`x'"=="Massachusetts" {
			loc y = -.45
		}
		else if "`x'"=="South Carolina" {
			loc y = -1.25
		}
		*** Impute the within-district results from calibration section
		else if "`x'"=="North Carolina" {
			loc y3 = -1.38
		}
		*** Impute the within-district results from calibration section
		else if "`x'"=="New York" {
			loc y1 = -0.38
			loc y2 = -1.41
			loc y3 = -1.49
		}
		
		*** For all reform states, we want to calculate the raw turnout
		*** (votes cast/# of members) for each place+office. The coefficients on 
		*** i.pre are the number of standard deviations away from the z-score when the 
		*** franchise qualification is set to 0 (ie., from the constant in the 
		*** model). 
						
		*** z_0 = constant term 
		*** z_1 = coefficient for pre==1
		*** z_2 = coefficient for pre==2
		*** raw number for low threshold (constant) z-score	: (z_0*s)+ �
		*** raw number for medium threshold z-score			: ((z_0-z_1)*s)+ � 
		*** raw number for high threshold z-score			: ((z_0-z_2)*s)+ � 
		
		*** raw number of disenfranchsied					: z_2*s
		
		*** We calculate this for all place+offices and calculate an average 
		*** reduction in turnout due to franchise qualifications across the state.
		*** Since we are imputing a state-wide estimate to local results, these 
		*** local estimates are often incompatible with observed data. But they 
		*** suggest what the magnitude of disenfranchisement would have been had the
		*** statewide estimate occurred in every unit.
		
		tempvar mean mean_post sd raw_dis per_dis per_dis_1 last_ob
		if "`x'"=="New York" {
			qui bys newID (date1): egen `mean'  = mean(totalNew) if state=="`x'" & (office=="Governor" | office=="State Senate")
			qui bys newID (date1): egen `mean_post' = mean(totalNew) if state=="`x'" & (office=="Governor" | office=="State Senate") & pre==0
			qui bys newID (date1): egen `sd' = sd(totalNew)	 if state=="`x'" & (office=="Governor" | office=="State Senate")
			qui gen `raw_dis' = (`y2'*`sd')  if state=="`x'" & (office=="Governor" | office=="State Senate")	
			qui gen `per_dis' = (`raw_dis')/`mean_post'  if state=="`x'" & (office=="Governor" | office=="State Senate")	
			qui bys newID (date1): egen `per_dis_1' = mean(`per_dis')
			qui bys newID (date1) : gen `last_ob' = _n==_N
			qui summ `per_dis_1' if year>=`year_1' & year<=`year_2' & `last_ob'==1
			loc j = round(r(mean),0.01)
			noisily di in yellow "`x' (High Threshold): " in green "`j'"
			
			drop `mean' `mean_post' `sd' `raw_dis' `per_dis' `per_dis_1' `last_ob'
			qui bys newID (date1): egen `mean' = mean(totalNew) if state=="`x'" & (office=="Assembly" | office=="U.S. House of Representatives")
			qui bys newID (date1): egen `mean_post' = mean(totalNew) if state=="`x'" & (office=="Assembly" | office=="U.S. House of Representatives") & pre==0
			qui bys newID (date1): egen `sd' = sd(totalNew)	 if state=="`x'" & (office=="Assembly" | office=="U.S. House of Representatives")
			qui gen `raw_dis' = (`y1'*`sd')  if state=="`x'" & (office=="Assembly" | office=="U.S. House of Representatives")	
			qui gen `per_dis' = (`raw_dis')/`mean_post'  if state=="`x'" & (office=="Assembly" | office=="U.S. House of Representatives")	
			qui bys newID (date1) : egen `per_dis_1' = mean(`per_dis')
			qui bys newID (date1) : gen `last_ob' 	 = _n==_N
			qui summ `per_dis_1' if `last_ob'==1
			loc j1 = round(r(mean),0.01)
			noisily di in yellow "`x' (Low Threshold): " in green "`j1'"
			
			drop `mean' `mean_post' `sd' `raw_dis' `per_dis' `per_dis_1' `last_ob'
			qui bys place date1: egen `mean' 		= mean(totalNew) if state=="`x'" & level==2 & year>=1816 & year<=1821
			qui bys place date1: egen `mean_post' 	= mean(totalNew) if state=="`x'" & level==2 & year>=1816 & year<=1821 & highThreshold==0
			qui bys place date1: egen `sd' 			= sd(totalNew)	 if state=="`x'" & level==2 & year>=1816 & year<=1821
			qui gen `raw_dis' = (`y3'*`sd')  if state=="`x'" & level==2 
			qui gen `per_dis' = (`raw_dis')/`mean_post'  if state=="`x'" & level==2
			qui bys newID (date1) : egen `per_dis_1' = mean(`per_dis')
			qui bys newID (date1) : gen `last_ob' 	 = _n==_N
			qui summ `per_dis_1' if `last_ob'==1 & year<=`k'
			loc j2 = round(r(mean),0.01)
			noisily di in yellow "`x' (Within-District): " in green "`j2'"
			drop `mean' `mean_post' `sd' `raw_dis' `per_dis' `per_dis_1' `last_ob'
			
			/*** compare to the old way.
			qui bys place date1: egen `a2' = mean(totalNew) if state=="`x'" & level==2 & year>=1816 & year<=1821
			qui bys place date1: egen `a5' = mean(totalNew) if state=="`x'" & level==2 & year>=1816 & year<=1821 & highThreshold==0
			qui bys place date1: egen `b2' = sd(totalNew)	 if state=="`x'" & level==2 & year>=1816 & year<=1821
			qui gen `c2' = (`y3'*`b2')+`a2'  if state=="`x'" & level==2
			qui gen `d2' = (`a2'-`c2')/`a5'  if state=="`x'" & level==2
			qui summ `d2' if year<=`k' 
			loc j2 = round(r(mean),0.01)
			noisily di in yellow "`x' (Within-District): " in green "`j2'"
			*/
			
		}
		else if "`x'"=="North Carolina" {
			qui bys place date1: egen `mean' = mean(totalNew) if state=="`x'" & level==2
			qui bys place date1: egen `mean_post' = mean(totalNew) if state=="`x'" & level==2 & highThreshold==0
			qui bys place date1: egen `sd' = sd(totalNew)	if state=="`x'" & level==2
			qui gen `raw_dis' = (`y3'*`sd')  				if state=="`x'" & level==2
			qui gen `per_dis' = (`raw_dis')/`mean_post'		if state=="`x'" & level==2
			qui bys newID (date1) : egen `per_dis_1' = mean(`per_dis')
			qui bys newID (date1) : gen `last_ob' 	 = _n==_N
			qui summ `per_dis_1' if `last_ob'==1
			loc j2 = round(r(mean),0.01)
			noisily di in yellow "`x' (Within-District): " in green "`j2'"
			drop `mean' `mean_post' `sd' `raw_dis' `per_dis' `per_dis_1' `last_ob'
		}
		else {
			qui bys newID (date1): egen `mean'		= mean(totalNew) if state=="`x'" & year>=`year_1' & year<=`year_2'
			qui bys newID (date1): egen `mean_post'	= mean(totalNew) if state=="`x'" & pre==0  & year<=`year_2'
			qui bys newID (date1): egen `sd' 		= sd(totalNew)	 if state=="`x'" & year>=`year_1' & year<=`year_2'
			qui gen `raw_dis' = (`y'*`sd') if state=="`x'"
			qui gen `per_dis' = (`raw_dis')/`mean_post'  if state=="`x'"
			qui bys newID (date1) : egen `per_dis_1' = mean(`per_dis')
			qui bys newID (date1) : gen `last_ob' 	 = _n==_N
			qui summ `per_dis_1' if `last_ob'==1
			loc j = round(r(mean),0.01)
			noisily di in yellow "`x': " in green "`j'"
		} 
		
	}
restore


********************************************************************************
********************	 Supplemental Material 	********************************
********************************************************************************

*** Much of the analyses for the supplemental material have already been done 
*** above. An additional analysis is to examine the effect of "reform" on 
*** non-reforming states. The analysis across states (above) is presented in 
*** the main text. The supplemental material includes state-by-state analyses
*** of non-reforming states using the randomly generated state-level placebo.

*** The results point to the difficulties of evaluating the impact of suffrage 
*** reform in cross-sectional data. Many are substantial and significant, despite
*** no actual reform having taken place. This underscores the importance of the 
*** causally identified analyses for NC and NY.

levelsof state if refState==0 & zvote!=., local(placebo)
foreach x in `placebo' {
	local y = subinstr("`x'", " ","",.)
	qui summ year if placebo==1 & state=="`x'"
	local k = r(max)
	local year_1 = `k'-5
	local year_2 = `k'+5
	
	** Use locally specified z-scores
	tempvar a b c
	qui bys newID (date1): egen `a' = mean(totalNew) if year>=`year_1' & year<=`year_2' & state=="`x'"
	qui bys newID (date1): egen `b' = sd(totalNew)   if year>=`year_1' & year<=`year_2' & state=="`x'"
	qui bys newID (date1): gen `c' = (totalNew-`a')/`b'  if year>=`year_1' & year<=`year_2' & state=="`x'"

	eststo pl_`y': xtreg zvote placebo if refState==0 & state=="`x'" & year>=`year_1' & year<=`year_2', fe robust
	margins, over(placebo)
	marginsplot, recast(scatter) xsc(reverse) name(pl_`y', replace) ///
		plotopts(lw(thin) mlc(black) mcol(white)) ciopts(lw(thin) lc(black))	///
		graphreg(col(none)) ylabel(, nogrid angle(h) labsize(vsmall)) ytitle("")	///
		xtitle("") xlabel(0 "Post-Placebo" 1 "Pre-Placebo", labsize(vsmall))	title("`x'", size(small) col(black) )
	
}

********************************************************************************
**************	 Create Tables and Combine Figures 	  **************************
********************************************************************************

****************				Main Text 				************************

*** Figures
graph combine Delaware Maryland NewJersey SouthCarolina Connecticut Massachusetts NewYork NoChange, cols(4) imargin(none) ///
		graphreg(col(white)) ycommon xcommon l1title("Standardized Votes Cast", size(vsmall)) 	///
		note("States with initially high qualifications shown in black, medium or low qualifications in gray. Horizontal lines indicate mean and two SDs above""and below the mean.", size(vsmall))
graph export "Figures/Figure-5.pdf", replace	

*** Tables
*** Table 5 in the main text shows the coefficient and standard errors from the
*** state-by-state analysis of reforming states. The full tables go in the 
*** supplemental material, and a summary table is produced for the main text. 
*** To do this, I extract from each analysis the coefficient and standard error 
*** for franchise qualication and create a summary table. 
esttab all placebo ref_Delaware_5 ref_Maryland_5 ref_NewJersey_5  ref_Connecticut_5 ref_Massachusetts_5 ref_NewYork_5 ref_SouthCarolina_5, cells(b(fmt(%9.3f)) se(par fmt(%9.3f))) scalars(F df_m df_r) keep(1.pre 2.pre placebo) replace  
capture mat drop C
matrix C = r(coefs)
local rnames : rownames C
local models : coleq C
local models : list uniq models
local i 0
foreach name of local rnames {
	local ++i
    local j 0
    capture matrix drop b
    capture matrix drop se
    foreach model of local models {
        local ++j
        matrix tmp = C[`i', 2*`j'-1]
        if tmp[1,1]<. {
            matrix colnames tmp = `model'
            matrix b = nullmat(b), tmp
            matrix tmp[1,1] = C[`i', 2*`j']
            matrix se = nullmat(se), tmp
        }
    }
    ereturn post b
    quietly estadd matrix se
    eststo threshold`i'
}


esttab threshold1 threshold2 threshold3 using  "Tables/Table-5.tex", wide se(a2) b(a2) label title(Effect of Franchise Qualifications on Turnout) 									///
	mtitles("Medium" "High" "Placebo") nogaps nodepvars nostar compress noconstant nonotes nonumbers 					///
	order(all  ref_Delaware_5 ref_Maryland_5 ref_NewJersey_5  ref_Connecticut_5 ref_Massachusetts_5 ref_NewYork_5 ref_SouthCarolina_5 placebo)	///
	coeflabels(all "All States" placebo "Other States" ref_Delaware_5 "Delaware" ref_Maryland_5 "Maryland" ref_NewJersey_5 "New Jersey" ref_SouthCarolina_5 "South Carolina" ref_Connecticut_5 "Connecticut" ref_Massachusetts_5 "Massachusetts" ref_NewYork_5 "New York")	///
	stats() noobs			///
	nolines prehead(\begin{table}[hbt!]\centering `"\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}"' \caption{Effect of Suffrage Qualifications on Turnout} \label{tab:5} ///
	\begin{tabular}{l*{6}{c}} \toprule)	posthead(\midrule) prefoot(\midrule)  													///
	postfoot(\bottomrule \end{tabular} \floatnote{District/Election FE in all models. Standard errors clustered at state-level for multi-state models. Time trend included in multi-state models; all others limited to 10 year window around moment of reform.} \end{table})   tex replace


		
****************			Supplemental Material			********************
*** Figures
graph combine all placebo ref_Delaware ref_Maryland ref_NewJersey ref_SouthCarolina ref_Connecticut ref_Massachusetts ref_NewYork, col(3) ycommon imargin(tiny) graphreg(col(white)) 
graph export "Figures/Supplemental/Supplemental-Figure-6.pdf", replace

*** Tables
*** Table A7: the full results summarized in Table 5 in the main text. 

esttab all ref_Delaware_5 ref_Maryland_5 ref_NewJersey_5 ref_SouthCarolina_5 ref_Connecticut_5 ref_Massachusetts_5 ref_NewYork_5 ///
	using "Tables/Supplemental/Supplemental-Table-7.tex", label 	///
	drop(0.pre)  b(a2) se(a2) coeflabel(1.pre "Med Threshold" 2.pre "High Threshold" year "Year" _cons "Constant") ///
	title(Effect of Franchise Qualifications on Standardized Turnout) 	///
	mtitles("All" "DE" "MD" "NJ" "SC" "CT" "MA" "NY" ) nogaps nodepvars	///
	nostar compress nonumbers  stats(N N_g F, fmt(%9.0g %9.0f %9.0f) label("N" "Panel Units" "F-value")) 		///
	nolines prehead(\begin{table}[hbt!]\centering \caption{@title} \label{tab:A7} \begin{tabular}{l*{@M}{c}} \toprule)		///		
	posthead(\midrule)  prefoot(\midrule) postfoot(\end{tabular}) ///
	substitute(\_ _) tex  fragment replace

*** Table A7 (contd): the same analysis as Table 5 in main text but using z-scores 
*** calculated on turnout in the 5 years before and 5 years after reform. 
esttab ref_Delaware_local ref_Maryland_local ref_NewJersey_local ref_SouthCarolina_local ref_Connecticut_local ref_Massachusetts_local ref_NewYork_local 	///
	using "Tables/Supplemental/Supplemental-Table-7.tex", noconstant label 	///
	drop(_cons 0.pre)  b(a2) se(a2) coeflabel(1.pre "Medium Threshold" 2.pre "High Threshold" year "Year" ) ///
	mtitles("DE" "MD" "NJ" "SC" "CT" "MA" "NY" ) nogaps nodepvars	///
	nostar compress nonumbers  stats(N N_g F, fmt(%9.0g %9.0f %9.0f) label("N" "Panel Units" "F-value")) 		///
	nolines prehead(\begin{tabular}{l*{@M}{c}} \toprule)		///		
	posthead(\midrule)  prefoot(\midrule)  postfoot(\bottomrule \end{tabular} 	///
	\floatnote{District/Election FE in all models. Robust standard errors. All models limited to 10 year window around moment of reform. Standardized turnout in lower panel calculated only for this 10 year period.} \end{table}) ///
	substitute(\_ _) tex  fragment append

*** Table A8: the same results as summarized in Table 5 in main text, but using 
*** different specifications of the window before and after reform. 
esttab ref_Delaware_5 ref_Maryland_5 ref_NewJersey_5  ref_Connecticut_5 ref_Massachusetts_5 ref_NewYork_5 ref_SouthCarolina_5, cells(b(fmt(%9.3f)) se(par fmt(%9.3f))) scalars(F df_m df_r) keep(1.pre 2.pre) replace  
capture mat drop C1
matrix C1 = r(coefs)
matrix coln C1 = DE:b DE:se MD:b MD:se NJ:b NJ:se CT:b CT:se MA:b MA:se NY:b NY:se SC:b SC:se
esttab ref_Delaware_10 ref_Maryland_10 ref_NewJersey_10  ref_Connecticut_10 ref_Massachusetts_10 ref_NewYork_10 ref_SouthCarolina_10, cells(b(fmt(%9.3f)) se(par fmt(%9.3f))) scalars(F df_m df_r) keep(1.pre 2.pre) replace  
capture mat drop C2
matrix C2 = r(coefs)
matrix coln C2 = DE:b DE:se MD:b MD:se NJ:b NJ:se CT:b CT:se MA:b MA:se NY:b NY:se SC:b SC:se
esttab ref_Delaware_15 ref_Maryland_15 ref_NewJersey_15  ref_Connecticut_15 ref_Massachusetts_15 ref_NewYork_15 ref_SouthCarolina_15, cells(b(fmt(%9.3f)) se(par fmt(%9.3f))) scalars(F df_m df_r) keep(1.pre 2.pre) replace  
capture mat drop C3
matrix C3 = r(coefs)
matrix coln C3 = DE:b DE:se MD:b MD:se NJ:b NJ:se CT:b CT:se MA:b MA:se NY:b NY:se SC:b SC:se
esttab ref_Delaware_20 ref_Maryland_20 ref_NewJersey_20  ref_Connecticut_20 ref_Massachusetts_20 ref_NewYork_20 ref_SouthCarolina_20, cells(b(fmt(%9.3f)) se(par fmt(%9.3f))) scalars(F df_m df_r) keep(1.pre 2.pre) replace  
capture mat drop C4
matrix C4 = r(coefs)
matrix coln C4 = DE:b DE:se MD:b MD:se NJ:b NJ:se CT:b CT:se MA:b MA:se NY:b NY:se SC:b SC:se
*eststo clear
forvalues t = 1(1)4 {
	local rnames : rownames C`t'
	local models : coleq C`t'
	local models : list uniq models
	local i 0
	foreach name of local rnames {
		local ++i
		local j 0
		capture matrix drop b
		capture matrix drop se
		foreach model of local models {
			local ++j
			matrix tmp = C`t'[`i', 2*`j'-1]
			if tmp[1,1]<. {
				matrix colnames tmp = `model'
				matrix b = nullmat(b), tmp
				matrix tmp[1,1] = C`t'[`i', 2*`j']
				matrix se = nullmat(se), tmp
			}
		}
		ereturn post b
		quietly estadd matrix se
		eststo threshold`i'`t'
	}
}
esttab threshold11 threshold21 threshold12 threshold22 threshold13 threshold23 threshold14 threshold24 	///
	using "Tables/Supplemental/Supplemental-Table-8.tex", se(a2) b(a2) label title(Effect of Franchise Qualifications on Turnout) 									///
	mgroup("10-Year" "20-Year" "30-Year" "40-Year", pattern(1 0 1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span )		///
	mtitles("Medium" "High" "Medium" "High" "Medium" "High" "Medium" "High" ) nogaps nodepvars compress noconstant nonotes nonumbers 					///
	coeflabels(DE "DE" MD "MD" NJ "NJ" SC "SC" CT "CT" MA "MA" NY "NY")	///
	nostar stats() noobs			///
	nolines prehead(\begin{table}[hbt!]\centering `"\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}"' \caption{Effect of Suffrage Qualifications on Turnout, Different Time Windows} \label{tab:A8} ///
	\begin{tabular}{l*{@M}{c}} \toprule)	posthead(\midrule) prefoot(\midrule)  													///
	postfoot(\bottomrule \end{tabular} \floatnote{District/Election FE in all models. Robust standard errors. All analyses limited to a different window of time around moment of reform.} \end{table})   tex replace

*** Table A9: The full results from the placebo tests 
esttab placebo pl_Alabama pl_Georgia pl_Illinois pl_Kentucky pl_Louisiana pl_Maine pl_Mississippi 	///
	using "Tables/Supplemental/Supplemental-Table-9.tex", noconstant label 	///
	drop(_cons)  b(a2) se(a2) coeflabel(placebo "Placebo" year "Year" ) ///
	title(Effect of Suffrage Qualifications on Standardized Turnout, Placebo States) 	///
	mtitles("Placebo States" "AL" "GA" "IL" "KY" "LA" "ME" "MS" ) nogaps nodepvars	///
	nostar compress nonumbers  stats(N N_g F, fmt(%9.0g %9.0f %9.0f) label("N" "Panel Units" "F-value")) 		///
	nolines prehead(\begin{table}[hbt!] \centering  `"\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}"'	`"\caption{@title} \label{tab:A9}"' \begin{tabular}{l*{@M}{c}} `"\toprule"')		///		
	posthead(\midrule)  prefoot(\midrule) postfoot(\midrule \end{tabular}) ///
	substitute(\_ _) tex  fragment replace

esttab pl_Missouri pl_NewHampshire pl_NorthCarolina pl_Ohio pl_Pennsylvania pl_RhodeIsland pl_Tennessee pl_Vermont pl_Virginia  	///
	using "Tables/Supplemental/Supplemental-Table-9.tex", noconstant label 	///
	drop(_cons)  b(a2) se(a2) coeflabel(placebo "Placebo" year "Year" ) ///
	title(Effect of Property Qualifications on Standardized Turnout,Placebo States) 	///
	mtitles("MO" "NH" "NC" "OH" "PA" "RI" "TN" "VT" "VA" ) nogaps nodepvars	///
	nostar compress nonumbers  stats(N N_g F, fmt(%9.0g %9.0f %9.0f) label("N" "Panel Units" "F-value")) 		///
	nolines prehead(\begin{tabular}{l*{@M}{c}} \toprule )		///		
	posthead(\midrule)  prefoot(\midrule) postfoot(\bottomrule \end{tabular} 	///
	\floatnote{District/Election FE in all models. Standard errors clustered at state-level for multi-state models. Time trend included in multi-state model. All other models limited to 10 year window around randomly assigned moment of reform.} \end{table}) ///
	substitute(\_ _) tex  fragment append

	
********************************************************************************
